package lang;


public class AtmDemo {


    public static void main(String[] args) throws InterruptedException {
        long user1 = System.currentTimeMillis();
        long user2 = System.currentTimeMillis();

        Account a1 = new Account(user1, 5000);

        Account a2 = new Account(user2, 3000);

        transfer(a1, a2, 100);

        System.out.println(a1.getBalance());
        System.out.println(a2.getBalance());



    }

    /**
     * 转账
     *
     * @param from
     * @param to
     * @param money
     * @return
     */
    public static boolean transfer(Account from, Account to, double money) {
        if (money > from.getBalance()) {
            System.out.printf("Account %s has no enough money to transfer.\n", from.getId());
            return false;
        }
        to.save(from.takeMoney(money));
        System.out.println(from.takeMoney(money));
        return true;
    }
}
